/*
 * GPUC
 * 
 * Copyright © 2008 Attila T. Áfra <attila.afra@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If
 * not, see <http://www.gnu.org/licenses/>.
 */

#include "CommonPrivate.h"

/*------------------------------------------------------------------------------------------------*/

GPUC_Bool GPUC_contextInitialized = 0;

#if defined(_WIN32)

#ifdef UNICODE
const wchar_t *GPUC_wglWindowClassName = L"GpuStream";
#else
const char    *GPUC_wglWindowClassName = "GpuStream";
#endif

HINSTANCE GPUC_wglModuleHandle;
WNDCLASS  GPUC_wglWindowClass;
HWND      GPUC_wglWindowHandle;
HDC       GPUC_wglDeviceContext;
HGLRC     GPUC_wglRenderingContext;

#else

Display    *GPUC_glxDisplay;
GLXPbuffer  GPUC_glxPbuffer;
GLXContext  GPUC_glxContext;

#endif

GPUC_Bool   GPUC_initialized     = 0;
GPUC_Bool   GPUC_glutInitialized = 0;
GLuint      GPUC_framebufferId;
GLenum     *GPUC_drawBuffers;
GLuint      GPUC_vertexShaderId;
int         GPUC_maxTextureRectSize;
int         GPUC_maxTextureImageUnitCount;
int         GPUC_maxDrawBufferCount;
int         GPUC_objectCount;
GPUC_Error  GPUC_error = GPUC_Error_NotInitialized;

/*------------------------------------------------------------------------------------------------*/

GPUC_API GPUC_Error
GPUC_getError()
{
    return GPUC_error;
}

/*------------------------------------------------------------------------------------------------*/

void GPUC_ignoreGlErrors()
{
    while (glGetError() != GL_NO_ERROR);
}

/*------------------------------------------------------------------------------------------------*/

GPUC_Bool GPUC_isGlError()
{
    return glGetError() != GL_NO_ERROR;
}

/*------------------------------------------------------------------------------------------------*/

int GPUC_checkGlError(GLenum error)
{
    GLenum currentError = glGetError();

    if (currentError == GL_NO_ERROR)
        return -1;

    do
    {
        if (currentError == error)
            return 0;

        currentError = glGetError();
    }
    while (currentError != GL_NO_ERROR);

    return 1;
}

/*------------------------------------------------------------------------------------------------*/
